package com.cdtye.itps.cms.service.pillar;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdtye.common.mybatiscore.base.BaseService;
import com.cdtye.itps.cms.dao.pillar.entity.JcwPillar;
import com.cdtye.itps.cms.dao.pillar.vo.JcwPillarVo;
import com.cdtye.itps.cms.mapper.pillar.JcwPillarMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class JcwPillarService extends BaseService<JcwPillarMapper, JcwPillar> {

    @Autowired
    private JcwPillarMapper baseMapper;

    /**
     * 支柱分页查询
     * @param vo
     * @return
     */
    public IPage<Map<String,Object>> listPage(JcwPillarVo vo){
        return baseMapper.listPage(vo.page(),vo);
    }

    /**
     * 支柱列表查询
     * @param vo
     * @return
     */
    public List<Map<String,Object>> getList(JcwPillarVo vo){
        return baseMapper.getList(vo);
    }

    /**
     * 通过区站名称和支柱号查询支柱
     * @param siteName
     * @param pillarNum
     * @return
     */
    public JcwPillar getPillarBySiteNameAndPillarNum( String siteName, String pillarNum){
        return baseMapper.getPillarBySiteNameAndPillarNum(siteName,pillarNum);
    }

    public int updatePillarImage(String pillarId,String imgPath){
        return baseMapper.updatePillarImage(pillarId,imgPath);
    }

    public List<JcwPillar> findPillarByPillarlNum(String pillarlNum, String seclineId, String directionId, String siteId) {

        //支柱号格式转换为四位数字，例：0001
//        pillarlNum = pillarlNum.replace("#", "");
//        if (pillarlNum.length() == 1){
//            pillarlNum = "000" + pillarlNum;
//        }else if (pillarlNum.length() == 2){
//            pillarlNum = "00" + pillarlNum;
//        }else if (pillarlNum.length() == 3){
//            pillarlNum = "0" + pillarlNum;
//        }
        QueryWrapper<JcwPillar> QueryWrapper = new QueryWrapper<>();
        QueryWrapper.eq("PILLAR_NUM", pillarlNum);
        //QueryWrapper.eq("SECLINE_ID", seclineId);
        //QueryWrapper.eq("DIRECTION_ID", directionId);
        QueryWrapper.eq("SITE_ID", siteId);
        return baseMapper.selectList(QueryWrapper);
    }

    public IPage<Map<String, Object>> pageList4Brain(JcwPillarVo vo) {
        return baseMapper.pageList4Brain(vo.page(),vo);
    }
}
